/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.smg.community.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javacommon.base.*;

import cn.org.rapid_framework.page.*;

import com.smg.community.model.CrmUser;
import com.smg.community.vo.query.CrmUserQuery;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */


import org.springframework.stereotype.Repository;


@SuppressWarnings("unchecked")
@Repository
public class CrmUserDao extends BaseIbatis3Dao<CrmUser,java.lang.Integer>{
	
	@Override
	public String getIbatisMapperNamesapce() {
		return "CrmUser";
	}
	
	public void saveOrUpdate(CrmUser entity) {
		if(entity.getId() == null) 
			save(entity);
		else 
			update(entity);
	}
	
	/**
	 * 根据用户名密码获取用户
	 * */
	public CrmUser getCrmUserByNameAndPwd(String userName,String userPass){
		Map<String, String> param = new HashMap<String, String>();
		param.put("userName", userName);
		param.put("userPass", userPass);
		return (CrmUser) getSqlSessionTemplate().selectOne("CrmUser.getByNameAndPwd", param);
	}
	public List<CrmUser> getBy(CrmUserQuery query){
		return (List<CrmUser>) getSqlSessionTemplate().selectList("CrmUser.getBy", query);
	}
	public int deleteByIds(String ids){
		Map<String, String> param = new HashMap<String, String>();
		param.put("ids", ids);
		return this.getSqlSessionTemplate().delete("CrmUser.deleteByIds", param);
	}
	@SuppressWarnings("rawtypes")
	public Page findPage(CrmUserQuery query) {
		return pageQuery("CrmUser.findPage",query);
	}
	
	public int updateByIds(String ids) {
		Map<String, String> param = new HashMap<String, String>();
		param.put("ids", ids);
		return this.getSqlSessionTemplate().update("CrmUser.updateByIds", param);
	}
	public int updateRoleIdsById(String roleIds,String id) {
		Map<String, String> param = new HashMap<String, String>();
		param.put("roleIds", roleIds);
		param.put("id", id);
		return this.getSqlSessionTemplate().update("CrmUser.updateRoleIdsById", param);
	}

	public List<CrmUser> getUserListByCityno(int cityno) {
		return this.getSqlSessionTemplate().selectList("CrmUser.getUserListByCityno",cityno);
	}
}
